package com.parrots.sample.security.support;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.jpa.support.JpaDaoSupport;
import org.springframework.stereotype.Service;

import com.parrots.sample.entity.Resource;
import com.parrots.sample.security.SecurityManager;

@Service("securityManager")
public class SecurityManagerSupport extends JpaDaoSupport implements SecurityManager {
    
    /* (non-Javadoc)
     * @see com.javaeye.sample.security.SecurityManager#loadUrlAuthorities()
     */
    @SuppressWarnings("unchecked")
	public Map<String, String> loadUrlAuthorities() {
        Map<String, String> urlAuthorities = new HashMap<String, String>();
        List<Resource> urlResources = getJpaTemplate().find("select resource from Resource resource WHERE resource.type = ?", Resource.TYPE_URL);
        for(Resource resource : urlResources) {
            urlAuthorities.put(resource.getValue(), resource.getRoleAuthorities());
        }
        return urlAuthorities;
    }

    
}
